Skip to content

database: dedup decisions within the filtered set - #4883

Open
Vigneshwarans32241 wants to merge 1 commit into
crowdsecurity:masterfrom
Vigneshwarans32241:fix/decision-dedup-filtered-set
Open

Vigneshwarans32241 wants to merge 1 commit into
crowdsecurity:masterfrom
Vigneshwarans32241:fix/decision-dedup-filtered-set

Conversation

@Vigneshwarans32241

Copy link
Copy Markdown

Bouncers filtering the decision stream silently missed bans.

longestDecisionForScopeTypeValue picks the longest decision for a value/type/scope over
the whole decisions table, while the origins and scenarios_* filters are applied to the
outer query only. A decision matching the filter is dropped as soon as a longer
filtered-out decision exists for the same value: with ?origins=crowdsec&startup=true, a
value that also has a longer CAPI decision returns {"new": [], "deleted": []} and the
bouncer never blocks it (#3373). The delta stream behaves the same way. dedup=false was
the only workaround.

The origin and scenario filters now also apply inside the dedup subquery, so the longest
decision is picked among the decisions the caller asked for. Behaviour without filters is
unchanged, and dedup still spans origins when several are requested.

Tested:

  • go test ./pkg/database/... -count=1
  • go test ./pkg/apiserver/controllers/v1/... -count=1
  • with the source change reverted (git checkout HEAD~1 -- pkg/database/decisions.go) the
    new test fails: 3 subtests, including origin_filter and delta_stream_with_origin_filter
  • I read the diff and ran the commands above myself.

AI: the patch and the test were drafted with an AI assistant; I reviewed the diff and
verified the reproduction and the test results myself.

The longest decision for a value/type/scope was picked over the whole table, so a
longer decision excluded by the query filters hid the matching one. A bouncer
asking for origin=crowdsec received nothing for a value that also had a longer
CAPI decision.

Apply the origin and scenario filters to the dedup subquery.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant